package com.emokili.ewa.frame.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.emokili.ewa.core.frame.entity.FrameEntity;
import com.emokili.ewa.core.frame.entity.FrameModelEntity;
import com.emokili.ewa.core.frame.entity.PlayListSettingEntity;
import com.emokili.ewa.core.frame.service.FrameModelService;
import com.emokili.ewa.core.frame.service.FrameService;
import com.emokili.ewa.core.frame.service.PlayListSettingService;
import com.emokili.ewa.core.frame.vo.FrameInfoVo;
import com.emokili.ewa.frame.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SettingServiceImpl implements SettingService {
    @Autowired
    private FrameService frameService;
    @Autowired
    private PlayListSettingService playListSettingService;
    @Autowired
    private FrameModelService frameModelService;

    @Override
    public FrameEntity getFrameSetting(String serialNumber) {
        FrameEntity frameServiceOne = frameService.getOne(new QueryWrapper<FrameEntity>().eq("serial_number", serialNumber));
        return frameServiceOne;
    }

    @Override
    public PlayListSettingEntity getPlayListSetting(String serialNumber) {
        PlayListSettingEntity playListSettingEntity = playListSettingService.getOne(new QueryWrapper<PlayListSettingEntity>().eq("serial_number", serialNumber));
        return playListSettingEntity;
    }

    @Override
    public void update(FrameInfoVo frameInfoVo) {
        FrameModelEntity frameModelEntity = new FrameModelEntity();
        frameModelEntity.setModel(frameInfoVo.getModel());
        frameModelEntity.setSerialNumber(frameInfoVo.getSerialNumber());
        frameModelEntity.setSoftwareVersion(frameInfoVo.getVersion());
        frameModelService.saveOrUpdate(frameModelEntity);
        FrameEntity frameEntity = new FrameEntity();
        frameEntity.setSerialNumber(frameInfoVo.getSerialNumber());
        FrameEntity one = frameService.getOne(new QueryWrapper<>(frameEntity));
        one.setMac(frameInfoVo.getMac());
        frameService.saveOrUpdate(one,new QueryWrapper<FrameEntity>().eq("id",one.getId()));
    }
}
